home *** CD-ROM | disk | FTP | other *** search
- /* curvr.c - assigns pass/fail grades on a curve system */
- #include "stdio.h"
-
- typedef struct /* definition of student data t */
- {
- char name[30] ;
- int grade ;
- } STUDENT ;
- main()
- {
- STUDENT class[400] ; /* student data for entire class */
- int ns ; /* count of students in the class */
- /* collect list of students and number grades */
- int i , cutoff ;
-
- printf(" Number of Students: \n") ;
- scanf("%d",&ns) ;
- printf(" Enter name and grade for each student \n") ;
- for( i=0 ; i < ns ; i=i+1)
- { scanf("%s %d",class[i].name, class[i].grade) ; }
-
- sortclass(class,ns) ;
- cutoff = (ns * 7) / 10 - 1 ;
- printf("\n") ;
- for( i=0 ; i < ns ; i=i+1)
- { printf("%-6s %3d", class[i].name, class[i].grade) ;
- if( i <= cutoff )
- printf(" Pass \n") ;
- else printf(" Fail \n") ;
- }
- }
-
- sortclass(st,nst) /* sort by numeric grade */
- STUDENT st[] ; /* array of student data structures */
- int nst ; /* number of students */
- {
- int i , j , pick ;
-
- for( i=0 ; i < (nst-1) ;i = i+1 )
- { pick = j ;
- for( j=i+1 ; j < nst ; j=j+1)
- { if( st[j].grade > st[pick].grade )
- pick = j ;
- }
- swap(& st[i] , & st[pick] ) ;
- }
- }
-
- swap(ps1,ps2)
- STUDENT *ps1 ;
- STUDENT *ps2 ;
- {
- STUDENT temp ;
-
- strcpy(temp.name, ps1->name ) ; temp.grade = ps1->grade ;
- strcpy(ps1->name,ps2->name) ; ps1->grade = ps2->grade ;
- strcpy(ps2->name,temp.name) ; ps2->grade = temp.grade ;
- }
-
-
-